package com.mystyle.le.weekproject.adapter;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.mystyle.le.weekproject.R;
import com.mystyle.le.weekproject.asynctaks.PictureAsyncTaks;
import com.mystyle.le.weekproject.beans.Seniority;
import com.mystyle.le.weekproject.intentfactbackcall.MyCallBack;
import com.mystyle.le.weekproject.utils.FileUtils;
import com.squareup.picasso.Picasso;

import java.util.List;

/**
 * Created by le on 2016/10/9.
 */
public class SeniorityFragmentAdapter extends BaseAdapter {

    private List<Seniority> list;
    private Context context;

    public SeniorityFragmentAdapter(List<Seniority> list, Context context) {
        this.list = list;
        this.context = context;
    }

    @Override
    public int getCount() {
        return list==null?0:list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        final ViewHolder holder;
        if (convertView==null){
            convertView = LayoutInflater.from(context).inflate(R.layout.seniorityfragmentadapter,parent,false);
            holder = new ViewHolder();
            holder.seniority_iv = (ImageView) convertView.findViewById(R.id.seniority_iv);
            holder.name_tv = (TextView) convertView.findViewById(R.id.name_tv);
            holder.ranking_tv = (TextView) convertView.findViewById(R.id.ranking_tv);
            holder.state_tv = (TextView) convertView.findViewById(R.id.state_tv);
            holder.theme_tv = (TextView) convertView.findViewById(R.id.theme_tv);
            convertView.setTag(holder);
        }else {
            holder = (ViewHolder) convertView.getTag();
        }
        Seniority seniority = list.get(position);
        holder.name_tv.setText(seniority.getName());
        holder.ranking_tv.setText("人气："+seniority.getRanking());
        holder.theme_tv.setText("类别："+seniority.getTheme());
        holder.state_tv.setText("状态"+seniority.getState());
        holder.seniority_iv.setImageResource(R.mipmap.bottombar_game_pressed);
        final String icon = seniority.getIcon();//图片地址
        Picasso.with(context).load(icon).into(holder.seniority_iv);

        return convertView;
    }

    class ViewHolder{
        ImageView seniority_iv;
        TextView name_tv,ranking_tv,state_tv,theme_tv;
    }

}
